<?php

#基础函数
include_once('_path.php');
include_once("../includes/init.php");

$ids = $_REQUEST['ids'];

if(empty($ids)){
    $_REQUEST['referrer'] = "index.php";
    redirect("请选择要删除的会员",1);
}

if(!is_array($ids)){
	$ids = array();
	$ids[0] = $_REQUEST['ids'];
}
	if(sizeof($ids)){
		foreach ($ids as $id) {
			if(is_numeric($id)){
				switch ($_REQUEST['type']) {
					case 'delete':
					        #删除会员信息
                                                $database->execute("DELETE FROM members_info WHERE id = ".$id);
                                                #删除files文件
                                                $rf = $database->queryArray("SELECT * FROM members_file WHERE uid=".$id);
                                                if(count($rs)>0){
                                                    foreach($rs as $r){
                                                        $database->execute("DELETE FROM members_file WHERE id = ".$r['id'].";");
                                                        @unlink(_CONST_UPLOAD_PATH.$r['file']);
                                                    }
                                                }
                                                #删除留言
                                                $rf = $database->queryArray("SELECT * FROM members_message WHERE uid=".$id);
                                                if(count($rs)>0){
                                                    foreach($rs as $r){
                                                        $database->execute("DELETE FROM members_message WHERE pid = ".$r['id'].";");
                                                        $database->execute("DELETE FROM members_message WHERE id = ".$r['id'].";");
                                                    }
                                                }
                                                #删除卡绑定
                                                $rf = $database->queryArray("SELECT * FROM members_card WHERE uid=".$id);
                                                if(count($rs)>0){
                                                    foreach($rs as $r){
                                                        $database->execute("UPDATE members_card SET status = 0 WHERE pid = ".$r['id'].";");
                                                        $database->execute("DELETE FROM members_card WHERE id = ".$r['id'].";");
                                                    }
                                                }
						break;
				}
			}
		}
	}

$_REQUEST['referrer'] = "index.php";
redirect("删除会员成功！");
?>